import java.util.Scanner;

public class HangmanTake2 {

    static String wordToGuess = "";
    static boolean isGameRunning = true;
    static String guess;
    static int lives = 6;
    static String guessedLetters = "";

    public static void main(String[] args) {
        System.out.println("Enter a secret word for another player to guess.  When you press enter, many lines will appear as a break.");
        Scanner input1 = new Scanner(System.in);
        wordToGuess = input1.nextLine().toUpperCase();
        for (int i = 10000; i != 0; i--)
            System.out.println("");
        for (int i = 0; i < wordToGuess.length(); i++)
            System.out.print("_ ");
        System.out.println();

        while (isGameRunning) {
            boolean won = true;

            System.out.println();
            System.out.println("Please guess a letter. No really, do it. COME ON BRO I SAID PLEASE!!!");
            Scanner input = new Scanner(System.in);
            guess = input.nextLine().substring(0, 1).toUpperCase();

            char guessChar = guess.charAt(0);
            guessedLetters += guess.charAt(0) + " ";

            for (int x = 0; x < wordToGuess.length(); x++) {
                char wordChar = wordToGuess.charAt(x);
                if (wordChar == guessChar || guessedLetters.contains(((Character) wordChar).toString())) {
                    System.out.print(wordChar);
                } else {
                    won = false;
                    System.out.print("_ ");
                }
            }
            System.out.println();

            if (!wordToGuess.contains(((Character) guessChar).toString())) {
                lives--;
                System.out.println("Oops! That letter isn't in the secret word.  You lost a life. You have " + lives + " left.");
            }
            System.out.println("The letters you have guessed so far are: " + guessedLetters);
            if (lives == 0) {
                isGameRunning = false;
                System.out.print("Sorry, you lost.  The secret word is " + wordToGuess + ".");
            }
            if (won) {
                isGameRunning = false;
                System.out.print("You Win! The secret word was " + wordToGuess + ".");
            }
        }
    }
}




































